package com.example.demos.web.interceptor;

import com.example.demos.mapper.MenuMapper;
import com.example.demos.util.CheckSonStr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String username =(String) request.getSession().getAttribute("username");
        if (username != null) {
          /*  String empMenu =(String) request.getSession().getAttribute("empMenu");
            String servletPath = request.getRequestURI();
            System.out.println("当前用户权限url："+empMenu);
            System.out.println("请求url："+servletPath);
            if (CheckSonStr.checkSonStr(servletPath,"/v2")){
                return true;
            }
            return CheckSonStr.checkSonStr(empMenu,servletPath);*/
            return true;
        } else {
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html");
            response.getWriter().print("<script> window.location.href='/login.html';</script>");
            return false;
        }
    }
}
